﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Jumpton.SFA.Server.BusinessRule.MasterData;
using Jumpton.SFA.Server.Entity;
using Jumpton.SFA.Server.BusinessRule;
using Jumpton.SFA.Server.BusinessRule.InStoreDataMeasures;
using Jumpton.Persistent;
using Jumpton.SFA.Server.BusinessRule.CallRoute;

public partial class CallRoute_Visit_Photo_Review : PageBase
{
    private decimal id = 0;
    private const string CHANNEL_ID = "id";
    private decimal visitid = 0;
    private const string VISIT_ID = "visitid";
    private string NAME = "";
    private string USERNAME = "";
    private string VISITTIME = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        // 在此处放置用户代码以初始化页面
        Response.Cache.SetCacheability(HttpCacheability.NoCache);//去掉页面缓存

        int intHistory = ViewState["History"] == null ? 0 : Int32.Parse(ViewState["History"].ToString());
        intHistory--;
        ViewState["History"] = intHistory.ToString();

        if (Request.QueryString[CHANNEL_ID] != null)
        {
            decimal.TryParse(Request.QueryString[CHANNEL_ID], out id);
        }
        if (Request.QueryString[VISIT_ID] != null)
        {
            decimal.TryParse(Request.QueryString[VISIT_ID], out visitid);
        }

        VISITS visit = new RouteManager().LoadVisits(visitid);
        Person person = new PersonManager().Load(int.Parse(visit.personid.ToString()));
        CUSTOMERS customer = new CustomerManager().Load(visit.CUSTOMERID);

        NAME = customer.NAME;
        USERNAME = person.Name;
        VISITTIME = visit.STOPTIME.ToString();

        if (!IsPostBack)
        {
            BindPhotoByVisit();
            ddlPhotoType.DataSource = new DictionaryItemsManager().GetItemList(DictionaryEnum.PhotoType, MyStateManager.DomainID);
            ddlPhotoType.DataTextField = "Name";
            ddlPhotoType.DataValueField = "dictionaryitemid";
            ddlPhotoType.DataBind();
            ddlPhotoType.Items.Insert(0, new ListItem("--所有--", ""));

            lblVisitHistoryMessage.Text = "[门店名称:  " + NAME + "]" + "      [巡店督导:  " + USERNAME + "]" + "      [拜访时间:  " + VISITTIME + "]";
        }
    }

    public void BindPhotoByVisit()
    {
        //dlPhotos.DataSource = CustomerPhotoManager.GetPhotoByVisit("", MyStateManager.DomainID, ddlPhotoType.SelectedValue, visitid, id);
        dlPhotos.DataBind();
    }

    protected void Unnamed1_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        HtmlAnchor a = e.Item.FindControl("anchor") as HtmlAnchor;
        if (a != null)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder("");
            sb.Append("javascript:window.showModalDialog('ReadPhoto.aspx?id=");
            sb.Append((e.Item.DataItem as DataRowView)["id"].ToString());
            sb.Append("','','dialogHeight:600px;dialogWidth:660px;left='+(screen.width-100)/2+',top='+(screen.height-100)/2+',center:yes;help:no;status:no;toolbar:no;')");
            a.HRef = sb.ToString();
        }
    }

    public string FormatURL(object id)
    {
        return ("../SMALLIMAGE.aspx?H=80&W=80&ID=" + id);
    }
    protected void ddlPhotoType_SelectedIndexChanged(object sender, EventArgs e)
    {
        BindPhotoByVisit();
    }
    protected void btnResearch_Click(object sender, EventArgs e)
    {
        Response.Redirect("Visit_History_List.aspx" + "?" + Request.QueryString);
    }
}
